//width、height调用时传入具体像素值，控制大小 ,不传则默认图像大小
//width、height调用时传入具体像素值，控制大小 ,不传则默认图像大小
function getBase64Image(img, width, height) {
    var canvas = document.createElement("canvas");
    canvas.width = width ? width : img.width;
    canvas.height = height ? height : img.height;

    var ctx = canvas.getContext("2d");
    ctx.drawImage(img, 0, 0, canvas.width, canvas.height);
    var dataURL = canvas.toDataURL();
    return dataURL;
}
function getCanvasBase64(img, whidth, height) {
    var image = new Image();
    //至关重要
    image.crossOrigin = '';
    image.src = img;
    return new Promise((resolve, reject) => {
        image.onload = function () {
            let base64 = getBase64Image(image, whidth, height)
            base64 ? resolve(base64) : reject("加载失败")
        }
    })

}
// getCanvasBase64(imgSrc)
//     .then(function (base64) {
//         console.log("方式二》》》》》》》》》", base64);
//     }, function (err) {
//         console.log(err);
//     });